<?php

namespace app\model;

use think\Model;

class Label extends Model
{
    //标签模型

    /**
     * 存入标签
     * @param $name
     * @return array
     */
    public function saveLabel( $name )
    {

        if ( $name ) {

            if(iconv_strlen($name,'utf-8') <= 10) {

                $isRepeat = $this->where( [ 'name' => $name ] )->count();

                if ( $isRepeat ) {

                    $return = [ 'status' => false, 'info' => '这个标签已经有啦' ];

                } else {

                    $re = $this->save( [ 'name' => $name ] );

                    if ( $re ) {

                        $return = [ 'status' => true, 'name' => $name, 'id' => $this->id ];

                    } else {

                        $return = [ 'status' => false, 'info' => '失败了,要不重新来一次?' ];

                    }

                }

            }else{

                $return = [ 'status' => false, 'info' => '写太长了,请控制在10个汉字以内' ];

            }

        } else {

            $return = [ 'status' => false, 'info' => '不写内容提交个P' ];

        }

        return $return;

    }
}
